package com.zlyx.easy.log.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

import com.zlyx.easy.log.WebShowLogHander;

@Configuration
@EnableWebSocketMessageBroker
@ConditionalOnClass(WebSocketMessageBrokerConfigurer.class)
public class LogSocketConfigurer {

	@Bean
	public WebSocketMessageBrokerConfigurer configWebSocket() {
		return new WebSocketMessageBrokerConfigurer() {
			@Override
			public void registerStompEndpoints(StompEndpointRegistry registry) {
				registry.addEndpoint("/easyLog").setAllowedOrigins("*").addInterceptors().withSockJS();
			}
		};
	}

	@Bean
	public WebShowLogHander configShowLogHandler() {
		return new WebShowLogHander();
	}
}
